/**
 * @author 徐楠
 * @date 2020/12/24 9:00
 * @version 1.0
 */

package edu.nuist.javaProjct.dao;

import edu.nuist.javaProjct.config.JdbcUtils;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

public class StudentDatasourceDao {
    private static final JdbcTemplate template = new JdbcTemplate(JdbcUtils.getDataSource());

    public int addData(String stuID,String name){
        String sql = "insert into studentdatasource(stuID,name) " + "values (?,?)";

        return template.update(sql,stuID,name);
    }

    public int deleteData(String stuID){
        String sql="DELETE FROM studentdatasource WHERE stuID=?";
        return template.update(sql,stuID);
    }


    public int updateData(String stuID,String name){
        String sql = "update studentdatasource set name=? where stuID=?";

        return template.update(sql,name,stuID);
    }

    public List<Map<String, Object>> listStudentMapData(){
        String sql="SELECT * FROM studentdatasource";
        return template.queryForList(sql);
    }
}
